#include<bits/stdc++.h>
using namespace std;
#define int long long

int num_rule;
string a, b;
string rule[100][2];
int ans = INT_MAX;

void dfs(int k, string x) {
	if (k >= ans)	return ;
	if (x == b) {
		ans = min(ans, k - 1);
		return ;
	}
	if (k > 11)	return ;

	for (int i = 1; i <= num_rule; i++) {
		int index = x.find(rule[i][0]);
		if (index == -1)	continue;
		string y = x.replace(index, rule[i][0].size(), rule[i][1]);
		dfs(k + 1, y);
	}
}

signed main() {
	cin >> a >> b;
	string x, y;
	while (cin >> x >> y) {
		rule[++num_rule][0] = x;
		rule[num_rule][1] = y;
	}
	dfs(1, a);
	if (ans < 11)
		cout << ans;
	else
		cout << "NO ANSWER!";
	return 0;
}
